package Risk.Moteur;

//~--- JDK imports ------------------------------------------------------------

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *  Class description
 *     @version    1.0, 07/12/26
 *   @author     Alexandre LIGUORI
 */
public class Continent {
    private String          nom;
    private ArrayList<Pays> paysContinent;
    private Plateau         plateau;
    private int             renfort;

    /**
     * Constructs ...
     *
     *
     * @param nom
     */
    public Continent(String nom, int renfort, Plateau plateau) {
        this.nom           = nom;
        this.paysContinent = new ArrayList<Pays>();
        this.renfort       = renfort;
        this.plateau       = plateau;
    }

    public int getRenfort() {
        return renfort;
    }

    public String getNom() {
        return nom;
    }

    public ArrayList<Pays> getPaysContinent() {
        return paysContinent;
    }

    public boolean ajoutePays(Pays val) {
        return this.paysContinent.add(val);
    }

    @Override
    public String toString() {
        return nom + " : " + renfort;
    }

    public void initialisationPays(String fic) {
        String          pays       = "";
        String          st_renfort = "";
        Pays            pays_TMP;
        FileReader      fl    = null;
        BufferedReader  bf    = null;
        String          ligne = null;
        StringTokenizer stok;

        try {
            File file = new File(fic);

            fl    = new FileReader(file);
            bf    = new BufferedReader(fl);
            ligne = bf.readLine();

            while (ligne != null) {
                stok = new StringTokenizer(ligne, " ");

                if (stok.nextToken().equals(this.getNom())) {
                    pays       = stok.nextToken();
                    st_renfort = stok.nextToken();
                    pays_TMP   = new Pays(pays, st_renfort, plateau);
                    ajoutePays(pays_TMP);
                }

                ligne = bf.readLine();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                bf.close();
                fl.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
